<template>
  <Layout ref="load" class="goods-detail bg-f8">
    <Navbar :title="navBarTitle" />
    <InviteWechat />
    <!-- <DetailShareBtn :detail="goods_detail" :goods-price="goodsPrice"/> -->
    <div class="swipe-box" :style="maxHeight">
      <van-swipe class="swipe" :autoplay="3000" :style="maxHeight">
        <van-swipe-item v-for="(item,index) in goods_detail.goods_images" :key="index">
          <img :src="item" :style="maxHeight" :onerror="$ERRORPIC.noGoods" />
        </van-swipe-item>
      </van-swipe>
      <DetailPlayVideoBtn v-if="goods_detail.video" :src="goods_detail.video | BASESRC" />
    </div>

    <DetailSeckill
      v-if="seckill_id"
      :price="goodsPrice | yuan"
      :market-price="marketPrice | yuan"
      :info="seckill_list"
      :load-data="loadData"
    />
    <DetailPresell
      v-if="presell_id"
      :info="presell_list"
      :params="presell_info"
      :load-data="loadData"
    />
    <DetailBargain
      v-if="bargain_id"
      :price="goodsPrice | yuan"
      :market-price="marketPrice | yuan"
      :info="bargain_list"
    />

    <DetailInfoPanel
      :goods_detail="goods_detail"
      :goodsPrice="goodsPrice"
      :marketPrice="marketPrice"
      :groupGoodsPrice="groupGoodsPrice"
      :presell_id="presell_id"
      :group_id="group_id"
      :seckill_id="seckill_id"
      :onlyRecord_id="onlyRecord_id"
      :bargain_id="bargain_id"
      :presell_list="presell_list"
      :bargain_list="bargain_list"
      :priceTag="priceTag"
      :digital-asset="digitalAsset"
    />

    <DetailCellAssembleGroup
      :list="group_record_list"
      :count="group_record_count"
      v-if="group_id && group_record_count > 0 && !onlyRecord_id"
      :load-data="loadData"
      @confirm="onConfirmGroup"
    />

    <DetailCellPresellGroup v-if="presell_id" :info="presell_list" :params="presell_info" />

    <DetailPromotion
      class="cell-group"
      :shop-name="goods_detail.shop_name"
      :full-cut-list="full_cut_list"
      :coupon-list="coupon_type_list"
      :point-info="give_point"
      :commission-info="commission_info"
    />

    <van-cell-group class="cell-group" v-if="!group_id">
      <van-cell :title="sku_selectedText" is-link @click="onSku" />
    </van-cell-group>

    <van-cell-group class="cell-group">
      <van-cell
        :border="false"
        :title="goods_detail.shop_name"
        icon="shop-o"
        is-link
        :to="{name:'shop-home',params:{shopid:goods_detail.shop_id}}"
        v-if="$store.state.config.addons.shop"
      >
        <span class="fs-12 text-secondary">进入店铺</span>
      </van-cell>
      <van-tabs v-model="tab_active">
        <van-tab v-for="(tab,index) in tabs" :title="tab.name" :key="index">
          <component
            :is="'Detail'+tab.type"
            :descript="(tab.type == 'Descript' ? goods_detail.description : '')"
            :attribute="(tab.type == 'Attribute' ? (goods_detail.goods_attribute_list ? goods_detail.goods_attribute_list : []) : '')"
          />
        </van-tab>
      </van-tabs>
    </van-cell-group>

    <van-sku
      v-model="showSku"
      :sku="goodsSku"
      :goods="goodsInfo"
      :goods-id="goods_detail.goods_id"
      close-on-click-overlay
      :quota="quota"
      :custom-stepper-config="customStepperConfig"
      @add-cart="onAddCart"
      @buy-clicked="onBuyNow"
      @sku-selected="onSkuSelect"
      @sku-close="onSkuClose"
      ref="getSkuData"
    >
      <div slot="sku-header-price" slot-scope="props">
        <div class="van-sku__goods-price" v-if="presell_id">
          <div>
            <van-tag plain type="danger">定金</van-tag>
            <span class="ml-10">{{presell_info.frontMoney | yuan}}</span>
          </div>
          <div>
            <van-tag plain type="danger">总价</van-tag>
            <span class="ml-10">{{presell_info.price | yuan}}</span>
          </div>
        </div>
        <div class="van-sku__goods-price" v-else>
          <span v-show="skuActionType !== 'groupBuy'">{{goodsPrice | yuan}}</span>
          <span v-show="skuActionType == 'groupBuy'">{{groupGoodsPrice | yuan}}</span>
          <van-tag
            plain
            type="danger"
            class="ml-10"
            v-if="group_id"
            v-show="skuActionType == 'groupBuy'"
          >拼团价</van-tag>
          <van-tag
            plain
            type="danger"
            class="ml-10"
            v-if="priceTag"
            v-show="skuActionType !== 'groupBuy'"
          >{{priceTag}}</van-tag>
        </div>
      </div>
      <div slot="sku-actions" slot-scope="props">
        <div class="van-sku-actions sku-action-group" v-if="goods_state === 1">
          <!-- channel_id 未完善加入购物车功能 暂时禁止 -->
          <van-button
            class="action-btn"
            bottom-action
            v-if="!presell_id && !is_virtualgoods && !bargain_id"
            v-show="skuAction.showCart"
            @click="props.skuEventBus.$emit('sku:addCart')"
            :disabled="channel_id ? true : disableOperation"
          >{{skuAction.textCart}}</van-button>
          <van-button
            class="action-btn"
            :type="skuActionType !== 'aloneBuy' ? 'primary' : ''"
            v-show="skuAction.showBuy"
            bottom-action
            @click="props.skuEventBus.$emit('sku:buy')"
            :disabled="skuAction.isDisable"
          >{{skuAction.textBuy}}</van-button>
          <van-button
            class="action-btn"
            type="primary"
            bottom-action
            v-if="group_id"
            v-show="skuAction.showGroupBuy"
            @click="props.skuEventBus.$emit('sku:buy')"
            :disabled="disableOperation"
          >{{skuAction.textBuy}}</van-button>
        </div>
        <div class="van-sku-actions" v-if="goods_state !== 1">
          <van-button class="action-btn" bottom-action disabled>{{goods_state_text}}</van-button>
        </div>
      </div>
    </van-sku>

    <CustomGroup type="3" :items="items" />

    <DetailBottomGoodsAction
      :detail="goods_detail"
      :goodsPrice="goodsPrice"
      :goods_state="goods_state"
      :seckill_id="seckill_id"
      :groupGoodsPrice="groupGoodsPrice"
      :onlyRecord_id="onlyRecord_id"
      :group_id="group_id"
      :presell_id="presell_id"
      :channel_id="channel_id"
      :is_virtualgoods="is_virtualgoods"
      :disableOperation="disableOperation"
      :bargain_list="bargain_list"
      :goods_state_text="goods_state_text"
      :seckill_list="seckill_list"
      @onSku="onSku"
    />
  </Layout>
</template>

<script>
import sfc from "@/utils/create";
import { Swipe, SwipeItem, Sku } from "vant";
import InviteWechat from "@/components/InviteWechat";
import CustomGroup from "@/components/CustomGroup";
import DetailInfoPanel from "./component/detail/InfoPanel";
import DetailDescript from "./component/detail/Descript";
import DetailAttribute from "./component/detail/Attribute";
import DetailEvaluate from "./component/detail/Evaluate";
import DetailPromotion from "./component/detail/Promotion";
// import DetailShareBtn from "./component/detail/ShareBtn";
import DetailSeckill from "./component/detail/Seckill";
import DetailCellAssembleGroup from "./component/detail/CellAssembleGroup";
import DetailPresell from "./component/detail/Presell";
import DetailCellPresellGroup from "./component/detail/CellPresellGroup";
import DetailBargain from "./component/detail/Bargain";
import DetailPlayVideoBtn from "./component/detail/PlayVideoBtn";
import DetailBottomGoodsAction from "./component/detail/BottomGoodsAction";

import { GET_GOODSDETAIL, ADD_CART } from "@/api/goods";
import { isEmpty } from "@/utils/util";
import { setSession } from "@/utils/storage";
import { _encode } from "@/utils/base64";
import { bindMobile } from "@/mixins";

export default sfc({
  name: "goods-detail",
  data() {
    return {
      tab_active: 0,
      tabs: [
        {
          name: "详情",
          type: "Descript"
        },
        {
          name: "属性",
          type: "Attribute"
        },
        {
          name: "评价",
          type: "Evaluate"
        }
      ],

      is_seckill:null,

      items: {},

      goods_detail: {},
      member_discount: 1,
      limit_discount: 1,
      member_is_label: null,
      is_allow_buy: true,

      coupon_type_list: [],
      full_cut_list: [],
      give_point: {
        is_point: 0,
        point: 0
      },
      commission_info: {},
      seckill_list: {},
      group_list: {},
      record_id: null,
      presell_list: {},
      bargain_list: {},

      showSku: false,
      goodsSku: {},
      goodsInfo: {},

      sku_selectedNum: 1,
      sku_selectedComb: null,

      group_sku_selectedNum: 1,
      group_sku_selectedComb: null,

      skuActionType: null,

      addCartFlag: true, // 防止重复点击添加多次购物车

      digitalAsset: {
        // 数字资产信息
        eth: 0,
        eos: 0,
        fee: 0
      }
    };
  },
  watch: {
    goodsid(id) {
      if (id) {
        this.$refs.load.init();
        this.loadData();
      }
    },
    skuActionType(n, o) {
      if (o && this.group_id) {
        this.resetSku();
      }
    }
  },
  mixins: [bindMobile],
  computed: {
    /**
     * 商品状态
     * 1  ==> 正常
     * -1 ==> 无库存
     * -2 ==> 无权限购买
     * -3 ==> 超出最大限购量
     * 0  ==> 下架
     */
    goods_state() {
      let state = null;
      if (this.goods_detail && this.goods_detail.state) {
        state = this.goods_detail.state;
        if (!this.is_allow_buy) {
          state = -2;
        } else if (this.countStock == 0) {
          state = -1;
        } else if (
          !this.group_id &&
          this.skuActionType != "groupBuy" &&
          this.goods_detail.max_buy === -1
        ) {
          state = -3;
        }
      } else if (this.goods_detail.state == 0) {
        state = 0;
      }
      return state;
    },
    goods_state_text() {
      let text = "";
      if (this.goods_state == -1) {
        text = "商品已售罄";
      } else if (this.goods_state == -2) {
        text = "无购买权限";
      } else if (this.goods_state == -3) {
        text = "已超出最大限购量";
      } else if (this.goods_state == 0) {
        text = "商品已下架";
      }
      return text;
    },
    goodsid() {
      return this.$route.params.goodsid;
    },
    shopkeeper_id() {
      //微店id
      return this.$route.query.shopkeeper_id
        ? this.$route.query.shopkeeper_id
        : "";
    },
    // 秒杀商品id  有则属秒杀商品
    seckill_id() {
      return !isEmpty(this.seckill_list) ? this.seckill_list.seckill_id : false;
    },
    // 秒杀状态 going:正在进行 unstart:未开始 ended:已结束
    seckill_status() {
      return !isEmpty(this.seckill_list)
        ? this.seckill_list.seckill_status
        : false;
    },
    // 拼团商品id 有则属拼团商品
    group_id() {
      return !isEmpty(this.group_list) ? this.group_list.group_id : false;
    },
    // 指定参团id
    onlyRecord_id() {
      return this.$route.query.record_id ? this.$route.query.record_id : null;
    },
    // 参团列表
    group_record_list() {
      return !isEmpty(this.group_list) ? this.group_list.group_record_list : [];
    },
    // 参团人数
    group_record_count() {
      return !isEmpty(this.group_list) ? this.group_list.group_record_count : 0;
    },
    // 渠道商id
    channel_id() {
      return this.$route.query.channel_id
        ? this.$route.query.channel_id
        : false;
    },
    // 预售id
    presell_id() {
      return this.presell_list.presell_id
        ? this.presell_list.presell_id
        : false;
    },
    // 预售状态
    presell_status() {
      return !isEmpty(this.presell_list)
        ? this.presell_list.state == 1
          ? "going"
          : "unstart"
        : false;
    },
    // 预售价格库存信息
    presell_info() {
      let obj = {};
      if (this.sku_selectedComb) {
        obj.frontMoney = this.sku_selectedComb.first_money;
        obj.tailMoney = this.sku_selectedComb.all_money - this.sku_selectedComb.first_money;
        obj.maxBuy = this.sku_selectedComb.max_buy;
        obj.stock = this.sku_selectedComb.over_num;
        obj.price = this.sku_selectedComb.all_money;
      } else {
        obj.frontMoney = this.presell_list.firstmoney;
        obj.tailMoney = this.presell_list.allmoney - this.presell_list.firstmoney;
        obj.maxBuy = this.presell_list.maxbuy;
        obj.stock = this.presell_list.presellnum;
        obj.price = this.presell_list.allmoney;
      }
      // console.log(obj)
      return obj;
    },
    // 砍价id
    bargain_id() {
      return this.bargain_list.bargain_id
        ? this.bargain_list.bargain_id
        : false;
    },
    // 砍价状态
    bargain_status() {
      return !isEmpty(this.bargain_list)
        ? this.bargain_list.status == 1
          ? "going"
          : "unstart"
        : false;
    },
    // 计时/次商品或虚拟商品
    is_virtualgoods() {
      return this.goods_detail.goods_type == 0 ||
        this.goods_detail.goods_type == 3
        ? true
        : false;
    },
    navBarTitle() {
      const title = this.goods_detail.goods_name;
      if (title) document.title = title;
      return title;
    },
    maxHeight() {
      return {
        maxHeight: document.body.offsetWidth + "px"
      };
    },
    // 显示商品价格(包含会员折扣和限时折扣)
    goodsPrice() {
      const member_discount = this.member_discount;
      const limit_discount = this.limit_discount;
      const isPromoteGoods =
        this.seckill_id || this.bargain_id || this.presell_id ? true : false; //是否属活动商品(秒杀、砍价、预售)
      const roundFix = !isPromoteGoods && this.member_is_label ? 0 : 2; //是否取整(活动商品时不取整)
      let discount_price = 0;
      let price = parseFloat(
        this.sku_selectedComb
          ? this.sku_selectedComb.price / 100
          : this.goodsSku.price
      ).toFixed(roundFix); // 商品售价
      let member_price = (price * member_discount).toFixed(roundFix); //会员价
      discount_price = (member_price * limit_discount).toFixed(roundFix); //（折扣价）会员限时折扣价
      return isPromoteGoods ? price : discount_price; // 秒杀商品及其他活动商品不参与任何折扣
    },
    // 市场价格
    marketPrice() {
      let price = this.sku_selectedComb
        ? this.sku_selectedComb.market_price
        : this.goods_detail.min_market_price;
      return price;
    },
    // 拼团商品价格
    groupGoodsPrice() {
      const roundFix = 2; //拼团价格不取整
      let group_price = parseFloat(
        this.group_sku_selectedComb
          ? this.group_sku_selectedComb.group_price / 100
          : this.goodsSku.group_price / 100
      ).toFixed(roundFix);
      return group_price;
    },
    // 活动价格标签
    priceTag() {
      const member_discount = this.member_discount;
      const limit_discount = this.limit_discount;
      let msg = false;
      if (this.seckill_id && this.seckill_status == "going") {
        msg = "秒杀价";
      } else {
        if (member_discount !== 1 || limit_discount !== 1) msg = "折扣价";
      }
      return msg;
    },
    // 转换sku列表数据 ( 元 => 分 )
    tranList() {
      const list = this.goods_detail.sku.list;
      list.forEach(e => {
        e.price = parseFloat(e.price) * 100;
        if (this.group_id) {
          e.group_price = parseFloat(e.group_price) * 100;
        }
        if (this.presell_id) {
          e.stock_num = parseInt(e.over_num);
        }
      });
      return list;
    },
    // 计算总库存
    countStock() {
      const list = this.goods_detail.sku ? this.goods_detail.sku.list : [];
      let stock = 0;
      if (list && !isEmpty(list)) {
        list.forEach(e => {
          if (this.presell_id) {
            stock +=
              e.presell_num > 0
                ? parseInt(e.over_num)
                : this.presell_list.presellnum
                ? this.presell_list.presellnum
                : 0;
          } else {
            stock += parseInt(e.stock_num);
          }
        });
      }
      return stock;
    },
    // 商品sku限购数量
    quota() {
      const $this = this;
      const goodsSku = isEmpty($this.goodsSku) ? null : $this.goodsSku;
      const sku_selectedComb = $this.sku_selectedComb;
      const group_sku_selectedComb = $this.group_sku_selectedComb;
      let quota = -1;
      // 秒杀限购
      if ($this.seckill_id && $this.seckill_status == "going" && goodsSku) {
        if (!goodsSku.none_sku && sku_selectedComb) {
          // console.log("有规格商品并已选规格");
          quota = sku_selectedComb.max_buy;
        } else if (goodsSku.none_sku) {
          // console.log("无规格商品");
          quota = goodsSku.list[0].max_buy;
        }
      } else if (
        $this.group_id &&
        goodsSku &&
        $this.skuActionType == "groupBuy"
      ) {
        // 拼团限购
        if (!goodsSku.none_sku && group_sku_selectedComb) {
          quota = group_sku_selectedComb.group_limit_buy;
        } else if (goodsSku.none_sku) {
          quota = goodsSku.list[0].group_limit_buy;
        }
      } else if ($this.presell_id && goodsSku) {
        // 预售限购
        if (!goodsSku.none_sku && sku_selectedComb) {
          quota = sku_selectedComb.max_buy;
        } else {
          quota = $this.presell_list.maxbuy;
        }
      } else if (goodsSku && goodsSku.max_buy) {
        // 普通商品单次限购量
        quota = goodsSku.max_buy;
      }
      // console.log("quota", quota);
      return quota;
    },
    // 限购数为0 禁止操作
    disableOperation() {
      let flag = false;
      // 活动限购为0则不能购买
      if (this.quota === 0 && (this.seckill_id || this.group_id)) {
        flag = true;
      } else if (this.presell_id) {
        if (this.presell_status == "unstart" || this.quota === 0) {
          flag = true;
        }
      }
      return flag;
    },
    // sku 步进器操作
    customStepperConfig() {
      const $this = this;
      const quotaText = $this.quota == -1 ? "" : "限购" + $this.quota + "件";
      return {
        quotaText,
        handleOverLimit: data => {
          const { action, limitType, quota, quotaUsed } = data;
          if (action === "minus") {
            $this.$Toast("至少选择一件！");
          } else if (action === "plus") {
            $this.$Toast(limitType === 1 ? "库存不足！" : `限购${quota}件！`);
          }
        },
        handleStepperChange: _num => {
          const num = parseInt(_num);
          // 限制最大输入数量
          const limitFlag = $this.quota > 0; // 活动限购量 真为限购 否为不限购
          let stock = 0; // 库存量
          if (!$this.goodsSku.none_sku && $this.sku_selectedComb) {
            stock = $this.sku_selectedComb.stock_num;
          } else {
            stock = $this.countStock;
          }
          let _limit = $this.quota > stock ? stock : $this.quota; //限购量
          let limitNum = num > _limit ? _limit : num; //当前数量不能大于限购数
          let limitStockNum = num > stock ? stock : num; //普通数量不能大于库存
          $this.sku_selectedNum = limitFlag ? limitNum : limitStockNum;
        }
      };
    },
    sku_selectedText() {
      const $this = this;
      let text = "";
      if ($this.goodsSku.none_sku) {
        text = "已选：" + $this.sku_selectedNum;
      } else {
        if ($this.sku_selectedComb) {
          text = "已选：" + $this.sku_selectedComb.sku_name;
        } else {
          text = "请选择规格";
        }
      }
      return text;
    },
    skuAction() {
      const $this = this;
      const type = $this.skuActionType;
      let obj = {};
      obj.showCart = true;
      obj.showBuy = true;
      obj.textCart = "加入购物车";
      obj.textBuy = "立即购买";
      obj.isDisable = this.disableOperation;
      if (type === "add") {
        obj.showCart = true;
        obj.showBuy = false;
        obj.textCart = "确定";
      } else if (type === "buy") {
        obj.showCart = false;
        obj.showBuy = true;
        obj.textBuy = "确定";
      } else if (type === "aloneBuy") {
        // 拼团单独购买
        obj.showCart = false;
        obj.showBuy = true;
        obj.showGroupBuy = false;
        obj.textBuy = "确定";
        if ($this.goods_detail.max_buy === -1) {
          obj.isDisable = true;
          obj.textBuy = "已超出最大限购量";
        }
      } else if (type === "groupBuy") {
        // 发起拼团
        obj.showCart = false;
        obj.showBuy = false;
        obj.showGroupBuy = true;
        obj.textBuy = "确定";
      } else {
        obj.showCart = true;
        obj.showBuy = true;
        obj.textCart = "加入购物车";
        if ($this.seckill_status) {
          if ($this.seckill_status == "going") obj.textBuy = "马上抢";
          if ($this.seckill_status == "unstart") {
            obj.textBuy = "即将开抢";
            obj.isDisable = true;
          }
        } else if ($this.presell_id) {
          obj.textBuy = "立即预定";
        } else {
          obj.textBuy = "立即购买";
        }
      }
      // console.log("skuAction类型==>", type, obj);
      return obj;
    }
  },
  mounted() {
    this.loadData();
  },
  methods: {
    getCustom(shop_id) {
      this.$store
        .dispatch("getCustom", {
          type: 3,
          shop_id
        })
        .then(data => {
          if (data.template_data) {
            this.items = data.template_data.items;
          }
        });
    },
    // 获取商品详情数据
    loadData() {
      const $this = this;
      const params = {};
      params.goods_id = $this.goodsid;

      if ($this.$route.query.seckill_id)
        params.seckill_id = $this.$route.query.seckill_id;
      if ($this.$route.query.record_id)
        params.record_id = $this.$route.query.record_id;
      if ($this.$route.query.channel_id)
        params.channel_id = $this.$route.query.channel_id;

      GET_GOODSDETAIL(params)
        .then(({ data }) => {
          const goods = data.goods_detail;
          $this.is_seckill=data.is_seckill
          if (data.is_allow_browse === false) {
            return $this.$refs.load.fail({
              errorType: "goods",
              errorText: "您自身等级无权限浏览该商品",
              showFoot: false
            });
          }
          $this.goods_detail = goods;
          $this.member_discount = data.member_discount; //会员折扣
          $this.limit_discount = data.limit_discount; //限时折扣
          $this.coupon_type_list = data.coupon_type_list; //优惠券
          $this.full_cut_list = data.full_cut_list; //满减送
          $this.seckill_list = data.seckill_list; //秒杀参数
          $this.group_list = data.group_list; //拼团参数
          $this.presell_list = data.presell_list; //预售参数
          $this.bargain_list = data.bargain_list; //砍价参数
          $this.give_point = data.give_point; // 返积分信息
          $this.member_is_label = data.member_is_label; //折扣是否取整
          $this.is_allow_buy =
            typeof data.is_allow_buy == "boolean" ? data.is_allow_buy : true; //是否有购买权限
          $this.commission_info = {
            // 返佣信息
            commission: data.commission,
            dis_point: data.dis_point
          };

          $this.goodsSku = {
            tree: goods.sku.tree ? goods.sku.tree : [],
            list: $this.tranList,
            price: goods.min_price,
            stock_num: $this.countStock, // 商品总库存
            collection_id: isEmpty(goods.sku.tree) ? $this.tranList[0].id : 0, // 无规格商品 skuId 取 collection_id，否则取所选 sku 组合对应的 id
            none_sku: isEmpty(goods.sku.tree), // 是否无规格商品
            max_buy: goods.max_buy
          };
          if ($this.group_id) {
            $this.goodsSku.group_price = $this.tranList[0].group_price;
            $this.goodsSku.group_limit_buy = $this.tranList[0].group_limit_buy;
          }
          $this.goodsInfo = {
            title: goods.goods_name,
            picture: goods.goods_images[0]
          };
          $this.digitalAsset = {
            eth: data.eth_market,
            eos: data.eos_market,
            fee: data.service_charge
          };
          $this.getCustom(goods.shop_id);
          $this
            .onShare({
              title: $this.goods_detail.goods_name,
              desc: `我刚刚在${$this.$store.getters.config.mall_name}发现了一个很不错的商品，赶快来看看吧。`,
              imgUrl: $this.goods_detail.goods_images[0],
              link: `${$this.$store.state.domain}/wap${$this.$route.fullPath}`
            })
            .then(() => {
              $this.$refs.load.success();
            });
        })
        .catch(() => {
          $this.$refs.load.fail();
        });
    },
    // 加入购物车
    onAddCart(data) {
      const $this = this;
      $this.bindMobile().then(() => {
        if (!$this.addCartFlag) return;
        $this.addCartFlag = false;
        let params = {};
        params.num = $this.sku_selectedNum > 0 ? $this.sku_selectedNum : 1;
        params.sku_id = data.selectedSkuComb.id;
        if ($this.shopkeeper_id) {
          params.shopkeeper_id = $this.shopkeeper_id; //微店id
          setSession("shopkeeper_id", $this.shopkeeper_id);
        }
        // if ($this.channel_id) params.channel_id = $this.channel_id;// 渠道商后台未完善加入购物车功能
        if ($this.seckill_id && $this.seckill_status == "going")
          params.seckill_id = $this.seckill_id;
        // console.log(params, $this.addCartFlag);
        // return;
        ADD_CART(params)
          .then(({ message }) => {
            $this.$Toast.success(message);
            if ($this.showSku) {
              $this.showSku = false;
              setTimeout(() => {
                $this.addCartFlag = true;
              }, 200);
            }
          })
          .catch(() => {
            $this.addCartFlag = true;
          });
      });
    },
    // 立即购买
    onBuyNow(data) {
      const $this = this;
      $this.bindMobile().then(() => {
        const params = {};
        params.order_tag = "buy_now";
        params.goodsType = $this.goods_detail.goods_type;
        if ($this.shopkeeper_id) {
          params.shopkeeper_id = $this.shopkeeper_id; //微店id
          setSession("shopkeeper_id", $this.shopkeeper_id);
        }
        params.sku_list = [];
        let sku_list_obj = {};
        sku_list_obj.num =
          $this.sku_selectedNum > 0 ? $this.sku_selectedNum : 1;
        sku_list_obj.sku_id = data.selectedSkuComb.id;
        if ($this.seckill_id) sku_list_obj.seckill_id = $this.seckill_id;
        if ($this.channel_id) sku_list_obj.channel_id = $this.channel_id;
        if ($this.group_id && $this.skuActionType == "groupBuy") {
          params.group_id = $this.group_id;
          if ($this.record_id) {
            params.record_id = $this.record_id;
          } else if ($this.onlyRecord_id) {
            params.record_id = $this.onlyRecord_id;
          }
        }
        if ($this.presell_id) params.presell_id = $this.presell_id;
        params.sku_list.push(sku_list_obj);
        // console.log(params);
        // return;
        $this.$router.push({
          name: "order-confirm",
          query: {
            params: _encode(JSON.stringify(params))
          }
        });
      });
    },
    // 参与拼团
    onConfirmGroup(id) {
      this.onSku("groupBuy");
      this.record_id = id; // 参与当前拼单的团id
    },
    // 选择规格
    onSkuSelect(data) {
      if (this.goodsSku.tree.length == 1) {
        this.goodsInfo.picture = data.selectedSkuComb
          ? data.skuValue.imgUrl
          : this.goods_detail.goods_images[0];
      }
      if (this.skuActionType !== "groupBuy") {
        this.sku_selectedComb = data.selectedSkuComb;
      } else {
        this.group_sku_selectedComb = data.selectedSkuComb;
      }
    },
    onSku(type) {
      const $this = this;
      $this.skuActionType = type;
      $this.showSku = true;
    },
    // 关闭sku
    onSkuClose(data) {
      // 参与拼单时，关闭sku清除record_id
      if (this.group_id && this.skuActionType == "groupBuy" && this.record_id) {
        this.record_id = null;
      }
    },
    // 重置已选sku
    resetSku() {
      const $this = this;
      if ($this.sku_selectedComb || $this.group_sku_selectedComb) {
        $this.$refs.getSkuData.resetSelectedSku($this.goodsSku.tree);
      }
      // 重置skustepper
      if ($this.$refs.getSkuData.$refs.skuStepper) {
        $this.$refs.getSkuData.$refs.skuStepper.setCurrentNum(1);
        $this.sku_selectedNum = 1;
      }
      $this.sku_selectedComb = null;
      $this.group_sku_selectedComb = null;
    }
  },
  components: {
    InviteWechat,
    DetailInfoPanel,
    DetailDescript,
    DetailAttribute,
    DetailEvaluate,
    DetailPromotion,
    // DetailShareBtn,
    DetailSeckill,
    DetailCellAssembleGroup,
    DetailPresell,
    DetailCellPresellGroup,
    DetailBargain,
    DetailPlayVideoBtn,
    CustomGroup,
    DetailBottomGoodsAction,
    [Swipe.name]: Swipe,
    [SwipeItem.name]: SwipeItem,
    [Sku.name]: Sku
  }
});
</script>

<style scoped>
.goods-detail {
  padding-bottom: 50px;
}

.swipe-box {
  position: relative;
  overflow: hidden;
}

.swipe img {
  width: 100%;
  height: auto;
  display: block;
}

.ml-10 {
  margin-left: 10px;
}

.mr-10 {
  margin-right: 10px;
}

.cell-group {
  margin: 10px 0;
}

.van-button--disabled {
  opacity: 1;
}
</style>